/*
 * create by Littleken at 2019/3/20 11:02
 */
package com.littleken.sellproject.exception.intercept;

import com.littleken.sellproject.VO.ResultVO;
import com.littleken.sellproject.enums.ResultEnum;
import com.littleken.sellproject.exception.SellException;
import com.littleken.sellproject.exception.SellerAuthorizeException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录异常处理
 */
@ControllerAdvice
public class SellExceptionHandler {

    /**
     * 拦截登录异常处理，并完成跳转
     * @return
     */
    @ExceptionHandler(value = SellerAuthorizeException.class)//需要拦截的异常
    public ModelAndView handlerAuthorizeException() {
        return new ModelAndView("index/index");
    }

    @ExceptionHandler(value = SellException.class)
    @ResponseBody
    //@ResponseStatus(HttpStatus.FORBIDDEN)//这个可以设置返回信息 200 403 400 500等
    public ResultVO handlerSellerException(SellException e) {
        return ResultVO.fail(e.getMessage());
    }


}
